package cn.wolfcode.p2p.mgrsite.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wolfcode.p2p.base.domain.SystemDictionaryItem;
import cn.wolfcode.p2p.base.query.SystemDictionaryItemQuery;
import cn.wolfcode.p2p.base.service.ISystemDictionaryItemService;
import cn.wolfcode.p2p.base.service.ISystemDictionaryService;
import cn.wolfcode.p2p.base.util.JSONResult;

/**
 *	字典明细控制器类
 */
@Controller
public class SystemDictionaryItemController {
	@Autowired
	private ISystemDictionaryItemService systemDictionaryItemService;
	@Autowired
	private ISystemDictionaryService systemDictionaryService;

	/**
	 * 字典明细列表
	 * @param model 视图
	 * @param qo 分页条件
	 * @return 明细列表
	 */
	@RequestMapping("/systemDictionaryItem_list")
	public String list(Model model, @ModelAttribute("qo") SystemDictionaryItemQuery qo){

		model.addAttribute("systemDictionaryGroups", systemDictionaryService.listAll());
		model.addAttribute("pageInfo", systemDictionaryItemService.query(qo));

		return "systemdic/systemDictionaryItem_list";
	}

	@RequestMapping("/systemDictionaryItem_update")
	@ResponseBody
	public Object update(SystemDictionaryItem sdi){
		JSONResult result = new JSONResult();

		try {
			systemDictionaryItemService.saveOrUpdate(sdi);
		} catch (Exception e) {
			e.printStackTrace();
			result.mark(e.getMessage());
		}
		return result;
	}
}
